package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class P3720 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3720.class.getResource("P3720.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		int[][] counts = new int[100][];
		for (int n = 1; n < counts.length; n ++) {
			counts[n] = count(n+1);
		}
		String line = stdin.readLine();
		while (line != null) {
			StringTokenizer st = new StringTokenizer(line);
			int n = Integer.valueOf(st.nextToken());
			int k = Integer.valueOf(st.nextToken());
			int count = 0;
			for (int i = 2; i <= n; i ++) {
				count += counts[i-1][k];
			}
			System.out.println(count);
			line = stdin.readLine();
		}
	}
	
	private static int[] count(int n) {
		
		int m = 1;
		List<Integer> remainders = new ArrayList<Integer>();
		remainders.add(1);
		List<Integer> t = new ArrayList<Integer>();
		int index = -1;
		do {
			m *= 10;
			int remainder = m%n;
			index = remainders.indexOf(remainder);
			if (index > -1) {
				if (remainder != 0) {
					t.add(m/n);
				}
				break;
			} else {
				t.add(m/n);
				remainders.add(remainder);
				m = remainder;
			}
		} while (true);
		
		int[] c = new int[10];
		for (int k: t) {
			c[k] ++;
		}
		return c;
	}
}